/****************************************************************************/
/* File: scs-clock.cpp                                                      */
/* Desc: Implementation file for the core clock type                        */
/* Created: 2014-11-10                                                      */
/* Revised: 2014-11-13                                                      */
/* Authors: Sterling P. de Mille                                            */
/****************************************************************************/

// specification file
#include "scs-clock.h"

SCSclock* SCSclock::m_pkSingleton = NULL;

// constructor
SCSclock::SCSclock ()
{
	assert(!m_pkSingleton);
	m_pkSingleton = this;

	m_iCurrentTicks = 0;
	m_iPreviousTicks = 0;
	m_iDeltaTicks = 0;
}

// destructor
SCSclock::~SCSclock ()
{
	assert(m_pkSingleton);
	m_pkSingleton = NULL;

	m_iCurrentTicks = 0;
	m_iPreviousTicks = 0;
	m_iDeltaTicks = 0;
}

// update frame time
void SCSclock::Update ()
{
	m_iPreviousTicks = m_iCurrentTicks;
	m_iCurrentTicks = SDL_GetTicks();
	m_iDeltaTicks = (m_iCurrentTicks - m_iPreviousTicks);
}

// update frame time
void SCSclock::Reset ()
{
	m_iCurrentTicks = SDL_GetTicks();
	m_iPreviousTicks = m_iCurrentTicks;
	m_iDeltaTicks = 0;
}

// time per frame
SCSfloat SCSclock::GetDT ()
{
	return (0.001f * m_iDeltaTicks);
}

// frames per second
SCSfloat SCSclock::GetFPS ()
{
	return ((m_iDeltaTicks != 0) ? (1.0f / GetDT()) : 0);
}

// singleton access
SCSclock* SCSclock::Singleton ()
{
	return m_pkSingleton;
}
